package dao;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Properties;

public class DataBaseConnect {
    public static Connection getConn(){
        //1.导入jar包druid
        //2.定义配置文件druid.properties
        //3.加载配置文件
        Properties prop=new Properties();
        try {
            prop.load(new FileInputStream("src/dao/druid.properties"));
            //4.获取连接池对象
            DataSource dataSource= DruidDataSourceFactory.createDataSource(prop);
            //5.获取数据库连接
            return dataSource.getConnection();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}

